package com.wetao.flexiblerichtextview;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.drawable.Drawable;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Html;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.ImageSpan;
import android.util.Base64;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget;
import com.daquexian.flexiblerichtextview.Base64Util;

import org.scilab.forge.jlatexmath.core.AjLatexMath;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

import fmath.conversion.ConvertFromMathMLToLatex;
import io.github.kbiakov.codeview.classifier.CodeProcessor;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private static final int REQUEST_EXTERNAL_STORAGE = 1;

    private static String[] PERMISSIONS_STORAGE = {
            "android.permission.READ_EXTERNAL_STORAGE",
            "android.permission.WRITE_EXTERNAL_STORAGE" };

    private static final String TAG = "MainActivity";
    private boolean isTurnPage = true;
    private ImageView img_show;
    private ImageView img_base64;
    private TextView tv_base64;
    private ImageView img_small;
    private ImageView img_small_base64;
    private TextView tv_small;
    Button btn_set_is_turn_page;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        verifyStoragePermissions(this);
        // train classifier on app start
        CodeProcessor.init(this);
        AjLatexMath.init(this); // init library: load fonts, create paint, etc.

        img_show = (ImageView)findViewById(R.id.img_show);
        img_base64 = (ImageView)findViewById(R.id.img_base64);
        tv_base64 = (TextView)findViewById(R.id.tv_base64);
        img_small = (ImageView)findViewById(R.id.img_small);
        img_small_base64 = (ImageView)findViewById(R.id.img_small_base64);
        tv_small = (TextView)findViewById(R.id.tv_small);
        btn_set_is_turn_page = (Button)findViewById(R.id.btn_set_is_turn_page);
        Button btn_see_latex  = (Button)findViewById(R.id.btn_see_latex);
        Button btn_webView  = (Button)findViewById(R.id.btn_webView);
        Button btn_test_empt_open = (Button)findViewById(R.id.btn_test_empt_open);
        Button btn_json_0 = (Button)findViewById(R.id.btn_json_0);
        Button btn_json_1 = (Button)findViewById(R.id.btn_json_1);
        Button btn_json_2 = (Button)findViewById(R.id.btn_json_2);
        Button btn_json_3 = (Button)findViewById(R.id.btn_json_3);
        Button btn_json_4 = (Button)findViewById(R.id.btn_json_4);
        Button btn_json_5 = (Button)findViewById(R.id.btn_json_5);
        Button btn_json_6 = (Button)findViewById(R.id.btn_json_6);
        Button btn_json_7 = (Button)findViewById(R.id.btn_json_7);
        Button btn_json_8 = (Button)findViewById(R.id.btn_json_8);
        Button btn_json_9 = (Button)findViewById(R.id.btn_json_9);
        Button btn_json_10 = (Button)findViewById(R.id.btn_json_10);
        Button btn_json_11 = (Button)findViewById(R.id.btn_json_11);
        Button btn_json_12 = (Button)findViewById(R.id.btn_json_12);
        Button btn_json_13 = (Button)findViewById(R.id.btn_json_13);
        Button btn_json_14 = (Button)findViewById(R.id.btn_json_14);
        Button btn_json_15 = (Button)findViewById(R.id.btn_json_15);
        Button btn_json_16 = (Button)findViewById(R.id.btn_json_16);
        Button btn_json_17 = (Button)findViewById(R.id.btn_json_17);
        Button btn_json_18 = (Button)findViewById(R.id.btn_json_18);
        Button btn_json_19 = (Button)findViewById(R.id.btn_json_19);
        Button btn_json_20 = (Button)findViewById(R.id.btn_json_20);
        Button btn_json_21 = (Button)findViewById(R.id.btn_json_21);
        Button btn_json_22 = (Button)findViewById(R.id.btn_json_22);
        Button btn_json_23 = (Button)findViewById(R.id.btn_json_23);
        Button btn_json_24 = (Button)findViewById(R.id.btn_json_24);
        Button btn_json_25 = (Button)findViewById(R.id.btn_json_25);
        Button btn_json_26 = (Button)findViewById(R.id.btn_json_26);
        Button btn_json_27 = (Button)findViewById(R.id.btn_json_27);
        Button btn_json_28 = (Button)findViewById(R.id.btn_json_28);
        Button btn_json_29 = (Button)findViewById(R.id.btn_json_29);
        Button btn_json_30 = (Button)findViewById(R.id.btn_json_30);
        Button btn_json_31 = (Button)findViewById(R.id.btn_json_31);
        Button btn_json_32 = (Button)findViewById(R.id.btn_json_32);
        Button btn_json_33 = (Button)findViewById(R.id.btn_json_33);
        Button btn_json_34 = (Button)findViewById(R.id.btn_json_34);
        Button btn_json_35 = (Button)findViewById(R.id.btn_json_35);
        Button btn_json_36 = (Button)findViewById(R.id.btn_json_36);
        Button btn_json_37 = (Button)findViewById(R.id.btn_json_37);
        Button btn_json_38 = (Button)findViewById(R.id.btn_json_38);
        Button btn_json_39 = (Button)findViewById(R.id.btn_json_39);


        Button btn_student_01 = (Button)findViewById(R.id.btn_student_01);
        Button btn_student_02 = (Button)findViewById(R.id.btn_student_02);
        Button btn_student_03 = (Button)findViewById(R.id.btn_student_03);

        btn_test_empt_open.setOnClickListener(this);
        btn_see_latex.setOnClickListener(this);
        btn_webView.setOnClickListener(this);
        btn_set_is_turn_page.setOnClickListener(this);
        btn_json_0.setOnClickListener(this);
        btn_json_1.setOnClickListener(this);
        btn_json_2.setOnClickListener(this);
        btn_json_3.setOnClickListener(this);
        btn_json_4.setOnClickListener(this);
        btn_json_5.setOnClickListener(this);
        btn_json_6.setOnClickListener(this);
        btn_json_7.setOnClickListener(this);
        btn_json_8.setOnClickListener(this);
        btn_json_9.setOnClickListener(this);
        btn_json_10.setOnClickListener(this);
        btn_json_11.setOnClickListener(this);
        btn_json_12.setOnClickListener(this);
        btn_json_13.setOnClickListener(this);
        btn_json_14.setOnClickListener(this);
        btn_json_15.setOnClickListener(this);
        btn_json_16.setOnClickListener(this);
        btn_json_17.setOnClickListener(this);
        btn_json_18.setOnClickListener(this);
        btn_json_19.setOnClickListener(this);
        btn_json_20.setOnClickListener(this);
        btn_json_21.setOnClickListener(this);
        btn_json_22.setOnClickListener(this);
        btn_json_23.setOnClickListener(this);
        btn_json_24.setOnClickListener(this);
        btn_json_25.setOnClickListener(this);
        btn_json_26.setOnClickListener(this);
        btn_json_27.setOnClickListener(this);
        btn_json_28.setOnClickListener(this);
        btn_json_29.setOnClickListener(this);
        btn_json_30.setOnClickListener(this);
        btn_json_31.setOnClickListener(this);
        btn_json_32.setOnClickListener(this);
        btn_json_33.setOnClickListener(this);
        btn_json_34.setOnClickListener(this);
        btn_json_35.setOnClickListener(this);
        btn_json_36.setOnClickListener(this);
        btn_json_37.setOnClickListener(this);
        btn_json_38.setOnClickListener(this);
        btn_json_39.setOnClickListener(this);


        btn_student_01.setOnClickListener(this);
        btn_student_02.setOnClickListener(this);
        btn_student_03.setOnClickListener(this);


        setBase64Image();
        setSmallImage();
        try {
            String strUT = URLDecoder.decode("%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20xmlns%3Awrs%3D%22http%3A%2F%2Fwww.wiris.com%2Fxml%2Fcvs-extension%22%20height%3D%2224%22%20width%3D%2285%22%20wrs%3Abaseline%3D%2219%22%3E%3C!--MathML%3A%20%3Cmath%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1998%2FMath%2FMathML%22%20display%3D%22inline%22%20mathvariant%3D%22italic%22%3E%3Cmo%3E%5B%3C%2Fmo%3E%3Cmo%3E-%3C%2Fmo%3E%3Cmn%3E5%3C%2Fmn%3E%3Cmsqrt%3E%3Cmn%3E2%3C%2Fmn%3E%3C%2Fmsqrt%3E%3Cmtext%3E%26%23xFF0C%3B1%3C%2Fmtext%3E%3Cmo%3E%5D%3C%2Fmo%3E%3C%2Fmath%3E--%3E%3Cdefs%3E%3Cstyle%20type%3D%22text%2Fcss%22%3E%40font-face%7Bfont-family%3A'math1da40657c9fece7e48d30af42d3'%3Bsrc%3Aurl(data%3Afont%2Ftruetype%3Bcharset%3Dutf-8%3Bbase64%2CAAEAAAAMAIAAAwBAT1MvMi7iBBMAAADMAAAATmNtYXDEvmKUAAABHAAAADRjdnQgDVUNBwAAAVAAAAA6Z2x5ZoPi2VsAAAGMAAAAcmhlYWQQC2qxAAACAAAAADZoaGVhCGsXSAAAAjgAAAAkaG10eE2rRkcAAAJcAAAACGxvY2EAHTwYAAACZAAAAAxtYXhwBT0FPgAAAnAAAAAgbmFtZaBxlY4AAAKQAAABn3Bvc3QB9wD6AAAEMAAAACBwcmVwa1uragAABFAAAAAUAAADSwGQAAUAAAQABAAAAAAABAAEAAAAAAAAAQEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAgICAAAAAg1UADev96AAAD6ACWAAAAAAACAAEAAQAAABQAAwABAAAAFAAEACAAAAAEAAQAAQAAIhL%2F%2FwAAIhL%2F%2F93vAAEAAAAAAAABVAMsAIABAABWACoCWAIeAQ4BLAIsAFoBgAKAAKAA1ACAAAAAAAAAACsAVQCAAKsA1QEAASsABwAAAAIAVQAAAwADqwADAAcAADMRIRElIREhVQKr%2FasCAP4AA6v8VVUDAAABAIABVQLVAasAAwAwGAGwBBCxAAP2sAM8sQIH9bABPLEFA%2BYAsQAAExCxAAblsQABExCwATyxAwX1sAI8EyEVIYACVf2rAatWAAAAAQAAAAEAANV4zkFfDzz1AAMEAP%2F%2F%2F%2F%2FWOhNz%2F%2F%2F%2F%2F9Y6E3MAAP8gBIADqwAAAAoAAgABAAAAAAABAAAD6P9qAAAXcAAA%2F7YEgAABAAAAAAAAAAAAAAAAAAAAAgNSAFUDVgCAAAAAAAAAACgAAAByAAEAAAACAF4ABQAAAAAAAgCABAAAAAAABAAA3gAAAAAAAAAVAQIAAAAAAAAAAQASAAAAAAAAAAAAAgAOABIAAAAAAAAAAwAwACAAAAAAAAAABAASAFAAAAAAAAAABQAWAGIAAAAAAAAABgAJAHgAAAAAAAAACAAcAIEAAQAAAAAAAQASAAAAAQAAAAAAAgAOABIAAQAAAAAAAwAwACAAAQAAAAAABAASAFAAAQAAAAAABQAWAGIAAQAAAAAABgAJAHgAAQAAAAAACAAcAIEAAwABBAkAAQASAAAAAwABBAkAAgAOABIAAwABBAkAAwAwACAAAwABBAkABAASAFAAAwABBAkABQAWAGIAAwABBAkABgAJAHgAAwABBAkACAAcAIEATQBhAHQAaAAgAEYAbwBuAHQAUgBlAGcAdQBsAGEAcgBNAGEAdABoAHMAIABGAG8AcgAgAE0AbwByAGUAIABNAGEAdABoACAARgBvAG4AdABNAGEAdABoACAARgBvAG4AdABWAGUAcgBzAGkAbwBuACAAMQAuADBNYXRoX0ZvbnQATQBhAHQAaABzACAARgBvAHIAIABNAG8AcgBlAAADAAAAAAAAAfQA%2BgAAAAAAAAAAAAAAAAAAAAAAAAAAuQcRAACNhRgAsgAAABUUE7EAAT8%3D)format('truetype')%3Bfont-weight%3Anormal%3Bfont-style%3Anormal%3B%7D%3C%2Fstyle%3E%3C%2Fdefs%3E%3Ctext%20font-family%3D%22Arial%22%20font-size%3D%2216%22%20font-style%3D%22italic%22%20text-anchor%3D%22middle%22%20x%3D%222.5%22%20y%3D%2219%22%3E%5B%3C%2Ftext%3E%3Ctext%20font-family%3D%22math1da40657c9fece7e48d30af42d3%22%20font-size%3D%2216%22%20font-style%3D%22italic%22%20text-anchor%3D%22middle%22%20x%3D%2211.5%22%20y%3D%2219%22%3E%26%23x2212%3B%3C%2Ftext%3E%3Ctext%20font-family%3D%22Arial%22%20font-size%3D%2216%22%20font-style%3D%22italic%22%20text-anchor%3D%22middle%22%20x%3D%2223.5%22%20y%3D%2219%22%3E5%3C%2Ftext%3E%3Cpolyline%20fill%3D%22none%22%20points%3D%2212%2C-16%2011%2C-16%205%2C0%202%2C-6%22%20stroke%3D%22%23000000%22%20stroke-linecap%3D%22square%22%20stroke-width%3D%221%22%20transform%3D%22translate(28.5%2C20.5)%22%2F%3E%3Cpolyline%20fill%3D%22none%22%20points%3D%225%2C0%202%2C-6%200%2C-5%22%20stroke%3D%22%23000000%22%20stroke-linecap%3D%22square%22%20stroke-width%3D%221%22%20transform%3D%22translate(28.5%2C20.5)%22%2F%3E%3Cline%20stroke%3D%22%23000000%22%20stroke-linecap%3D%22square%22%20stroke-width%3D%221%22%20x1%3D%2240.5%22%20x2%3D%2253.5%22%20y1%3D%224.5%22%20y2%3D%224.5%22%2F%3E%3Ctext%20font-family%3D%22Arial%22%20font-size%3D%2216%22%20font-style%3D%22italic%22%20text-anchor%3D%22middle%22%20x%3D%2246.5%22%20y%3D%2219%22%3E2%3C%2Ftext%3E%3Ctext%20font-family%3D%22Arial%22%20font-size%3D%2216%22%20font-style%3D%22italic%22%20text-anchor%3D%22middle%22%20x%3D%2266.5%22%20y%3D%2219%22%3E%26%23xFF0C%3B1%3C%2Ftext%3E%3Ctext%20font-family%3D%22Arial%22%20font-size%3D%2216%22%20font-style%3D%22italic%22%20text-anchor%3D%22middle%22%20x%3D%2281.5%22%20y%3D%2219%22%3E%5D%3C%2Ftext%3E%3C%2Fsvg%3E", "utf-8");
            Log.i(TAG, "--UTF-8转汉字： " + strUT);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        //String str = Html.fromHtml("<p style=\"line-height: 1.5;\">(2016秋&middot;杨浦区校级期中)己知集合U={a，b，c，d，e，f}，集合A={a，b，c，d}，A&cap;B={b}，∁<sub>U</sub>(A&cup;B)={f}，求集B.</p>").toString();
        String str = Html.fromHtml("<p style=\"line-height: 1.5;\">(2017･河北校级月考)已知q和n均为给定的大于1的自然数，设集合M={0，1，2，&hellip;，q&minus;1}，集合A={x|x=x<sub>1</sub>+x<sub>2</sub>q+&hellip;+x<sub>n</sub>q<sup>n</sup><sup>&minus;</sup><sup>1</sup>，x<sub>i</sub>&isin;M，i=1，2，&hellip;n}．当q=2，n=3时，用列举法表示集合A．</p>").toString();
        Log.i(TAG, "特殊字符串：" + str);

    }

    //然后通过一个函数来申请
    public static void verifyStoragePermissions(Activity activity) {
        try {
            //检测是否有写的权限
            int permission = ActivityCompat.checkSelfPermission(activity,
                    "android.permission.WRITE_EXTERNAL_STORAGE");
            if (permission != PackageManager.PERMISSION_GRANTED) {
                // 没有写的权限，去申请写的权限，会弹出对话框
                ActivityCompat.requestPermissions(activity, PERMISSIONS_STORAGE,REQUEST_EXTERNAL_STORAGE);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        setShowImage();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_set_is_turn_page:{
                isTurnPage = !isTurnPage;
                if(isTurnPage) {
                    btn_set_is_turn_page.setText("设置为滚动");
                } else {
                    btn_set_is_turn_page.setText("设置为翻页");
                }
            }break;
            case R.id.btn_test_empt_open:{
                startActivity(new Intent(this, EmptyActivity.class));
            }break;
            case R.id.btn_see_latex:{
                Log.i(TAG, "aaa");
                String mathMl="<math><mml><mi>f</mi></mml></math>";
                startActivity(new Intent(this, ExampleActivity.class));
                //String letexstr = ConvertFromMathMLToLatex.convertToLatex(mathMl);
                //Log.e(TAG, "bbb" + letexstr);
            }break;
            case R.id.btn_webView:{
                startActivity(new Intent(this, WebviewMainActivity.class));
            }break;
            case R.id.btn_json_0:{
                gotoQuestionAnalysisActivity(0);
            }break;
            case R.id.btn_json_1:{
                gotoQuestionAnalysisActivity(1);
            }break;
            case R.id.btn_json_2:{
                gotoQuestionAnalysisActivity(2);
            }break;
            case R.id.btn_json_3:{
                gotoQuestionAnalysisActivity(3);
            }break;
            case R.id.btn_json_4:{
                gotoQuestionAnalysisActivity(4);
            }break;
            case R.id.btn_json_5:{
                gotoQuestionAnalysisActivity(5);
            }break;
            case R.id.btn_json_6:{
                gotoQuestionAnalysisActivity(6);
            }break;
            case R.id.btn_json_7:{
                gotoQuestionAnalysisActivity(7);
            }break;
            case R.id.btn_json_8:{
                gotoQuestionAnalysisActivity(8);
            }break;
            case R.id.btn_json_9:{
                gotoQuestionAnalysisActivity(9);
            }break;
            case R.id.btn_json_10:{
                gotoQuestionAnalysisActivity(10);
            }break;
            case R.id.btn_json_11:{
                gotoQuestionAnalysisActivity(11);
            }break;
            case R.id.btn_json_12:{
                gotoQuestionAnalysisActivity(12);
            }break;
            case R.id.btn_json_13:{
                gotoQuestionAnalysisActivity(13);
            }break;
            case R.id.btn_json_14:{
                gotoQuestionAnalysisActivity(14);
            }break;
            case R.id.btn_json_15:{
                gotoQuestionAnalysisActivity(15);
            }break;
            case R.id.btn_json_16:{
                gotoQuestionAnalysisActivity(16);
            }break;
            case R.id.btn_json_17:{
                gotoQuestionAnalysisActivity(17);
            }break;
            case R.id.btn_json_18:{
                gotoQuestionAnalysisActivity(18);
            }break;
            case R.id.btn_json_19:{
                gotoQuestionAnalysisActivity(19);
            }break;
            case R.id.btn_json_20:{
                gotoQuestionAnalysisActivity(20);
            }break;
            case R.id.btn_json_21:{
                gotoQuestionAnalysisActivity(21);
            }break;
            case R.id.btn_json_22:{
                gotoQuestionAnalysisActivity(22);
            }break;
            case R.id.btn_json_23:{
                gotoQuestionAnalysisActivity(23);
            }break;
            case R.id.btn_json_24:{
                gotoQuestionAnalysisActivity(24);
            }break;
            case R.id.btn_json_25:{
                gotoQuestionAnalysisActivity(25);
            }break;
            case R.id.btn_json_26:{
                gotoQuestionAnalysisActivity(26);
            }break;
            case R.id.btn_json_27:{
                gotoQuestionAnalysisActivity(27);
            }break;
            case R.id.btn_json_28:{
                gotoQuestionAnalysisActivity(28);
            }break;
            case R.id.btn_json_29:{
                gotoQuestionAnalysisActivity(29);
            }break;
            case R.id.btn_json_30:{
                gotoQuestionAnalysisActivity(30);
            }break;
            case R.id.btn_json_31:{
                gotoQuestionAnalysisActivity(31);
            }break;
            case R.id.btn_json_32:{
                gotoQuestionAnalysisActivity(32);
            }break;
            case R.id.btn_json_33:{
                gotoQuestionAnalysisActivity(33);
            }break;
            case R.id.btn_json_34:{
                gotoQuestionAnalysisActivity(34);
            }break;
            case R.id.btn_json_35:{
                gotoBoxDataActivity(35);
            }break;
            case R.id.btn_json_36:{
                gotoBoxDataActivity(36);
            }break;
            case R.id.btn_json_37:{
                gotoQuestionAnalysisActivity(37);
            }break;
            case R.id.btn_json_38:{
                gotoQuestionAnalysisActivity(38);
            }break;
            case R.id.btn_json_39:{
                gotoQuestionAnalysisActivity(39);
            }break;
            case R.id.btn_student_01:{
                startActivity(new Intent(this, Student01Activity.class));
            }break;
            case R.id.btn_student_02:{
                startActivity(new Intent(this, Student02Activity.class));
            }break;
            case R.id.btn_student_03:{
                startActivity(new Intent(this, Student03Activity.class));
            }break;
        }
    }

    private void gotoQuestionAnalysisActivity(int index) {
        Intent intent = new Intent(this, QuestionAnalysisActivity.class);
        intent.putExtra("questionIndex", index);
        intent.putExtra("isTurnPage", isTurnPage);
        startActivity(intent);
    }
    private void gotoBoxDataActivity(int index) {
        Intent intent = new Intent(this, BoxDataActivity.class);
        intent.putExtra("questionIndex", index);
        intent.putExtra("isTurnPage", isTurnPage);
        startActivity(intent);
    }

    private void setBase64Image() {
        //将Base64编码字符串解码成Bitmap
        String base64String = "\nFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgo\nKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCABYAB4DASIA\nAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQA\nAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3\nODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWm\np6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEA\nAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSEx\nBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElK\nU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3\nuLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD6pooo\noAKKxYfFWiT+Lp/C8GoRSa7b2ovJrRAxMcRKgFmA2g/Mp2k7sMDjBBraoAK5D4teNIPAPgLU9dlM\nRuY08uzikx++uG4RcblLAH5mAOdqsR0rr6+dfj9DJ40+Nfw98AyJ/wAS051K7R7h0juI9zblKqMh\nhHBKFbOcykZXkkA7v9nnw4+k+Ao9b1GSK513xO/9s390qqN5m+dF4VcAK2dvIDO+ODXp9FFABXzh\n8KVfxP8AtT/ELxA+mxC20tHsBI7K5imVkgRlyAQXSCY5A4BKk88/R9eAfs4f8lT+NH/YaH/o+7oA\n9/ooooAK+cP2d9Vgh+Ofxc0hklNzdahNdowA2BIrmVWBOc5JnTHHY9OM/R9fOFzcz+E/2zRJdTWK\nWnifT0jDSOQUTygqLk4Akaa1CgfNkOB1PAB9H0UUUAFeK/tP6DfPoWh+NNFj8/UvCN6t+LdwzI8W\n5C5KqMna0cbH5lAQSEnpXtVRXdtBeWs1reQxT206NHLFKgZJEYYKsDwQQSCDQBn+FNesfFHhvTtb\n0qTfZX0KzR5KllyOUbaSAynKsMnBBHatWvMPhR4d1XwDr+t+FWiln8Kzu+paLcpvZLVGcCS0cs5K\nlSyMnHz/ALxs5yq+n0AFFFFABRRRQB//2Q==";
        Bitmap decodedByte =  Base64Util.base64ToBitmap(base64String);
        //设置ImageView图片
       img_base64.setImageBitmap(decodedByte);


        SpannableStringBuilder ssb = new SpannableStringBuilder();
        ssb.append("abcdefg");
        ssb.setSpan(new ImageSpan(this, decodedByte, ImageSpan.ALIGN_BOTTOM), 2, 3, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        //ssb.setSpan(new IconMarginSpan(decodedByte, 0), 0, 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        //ssb.setSpan(new DrawableMarginSpan(new BitmapDrawable(decodedByte)), 0, 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        tv_base64.setText(ssb);
    }

    private void setSmallImage() {
        //String url = "http://cdn.newpage.ink/b72673c409d14d80a20831b925cc7634.jpg";
        String url = "http://newpage-edu.oss-cn-beijing.aliyuncs.com/7ccfd4e408d14d54b71523c70050d488.jpg";
        //String url = "http://newpage-edu.oss-cn-beijing.aliyuncs.com/42a04c4a23044daab5d2c9bcf5cdbe0b.jpg";
        Glide.with(this).load(url).asBitmap().into(new SimpleTarget<Bitmap>() {
            @Override
            public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                //resource = Base64Util.bitmapZoom(resource, 2f, 2f);
                Log.i(TAG, "加载图片-成功");
                //img_small.setImageBitmap(resource);
                String str_base64 = Base64Util.bitmapToBase64(resource);
                //Log.i(TAG, "加载图片-成功：" + str_base64);
                Bitmap decodedByte = Base64Util.base64ToBitmap(str_base64);
                //img_small_base64.setImageBitmap(decodedByte);
                SpannableStringBuilder ssb = new SpannableStringBuilder();
                ssb.append("的镂空设计费拉客户给爱丽丝疯狂建档立卡恢复大师开发交流阿11111111111111111111111111111111111111111里山的客户发大水口附近阿里");
                ssb.setSpan(new ImageSpan(MainActivity.this, decodedByte, ImageSpan.ALIGN_BASELINE), 13, 14, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
                tv_small.setText(ssb);
            }

            @Override
            public void onLoadFailed(Exception e, Drawable errorDrawable) {
                super.onLoadFailed(e, errorDrawable);
                Log.i(TAG, "加载图片-失败");
            }
        });
    }
    private void setShowImage() {
        String url = "http://newpage-edu.oss-cn-beijing.aliyuncs.com/7d5e316ec75041cbb62b5434131b11ab.jpg";
        //String url = "http://newpage-edu.oss-cn-beijing.aliyuncs.com/1590721180109.jpg";
        //String url = "https://dss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo_top-e3b63a0b1b.png";
        Glide.with(this).load(url).dontAnimate()
                .diskCacheStrategy(DiskCacheStrategy.ALL).into(img_show);
    }

}